package com.yonyou.crm.bpub.refervalue.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.base.product.entity.ProductVO;
import com.yonyou.crm.base.product.service.ProductBizServiceImpl;
import com.yonyou.crm.bpub.refervalue.entity.ReferDataVO;
import com.yonyou.crm.common.page.entity.Page;

@Service
public class ProductRefervalue extends BaseRefervalue{

	@Autowired
	ProductBizServiceImpl service;
	
	@Override
	public <T extends Serializable> List<ReferDataVO> getRefervalues(Page<T> page, Map<String, Object> paraMap) {
		List<ProductVO> list = service.getRefervaluesForApp((Page<ProductVO>)page, paraMap);
		
		
		List<ReferDataVO> rsList = new ArrayList<ReferDataVO>();
		for (ProductVO vo : list) {
			ReferDataVO referDataVO = new ReferDataVO();
			referDataVO.setId(vo.getId().toString());
			referDataVO.setValue(vo.getName());
			List<String> itemDataList = new ArrayList<>();
			itemDataList.add(vo.getName());
			//TODO 根据funcode决定返回的数据内容
			
			/*
			//TODO 确认商机产品参照的业务逻辑是否需要分类、品牌、价格
			List<ReferItemVO> referItemVOs = new ArrayList<ReferItemVO>();
			ReferItemVO referItemVO = new ReferItemVO();
			referItemVO.setItemkey("productTypeId");
			if (vo.getPrdtypeId() == null) {
				referItemVO.setId("");
				referItemVO.setValue("");
			} else {
				referItemVO.setId(vo.getPrdtypeId().toString());
				referItemVO.setValue(vo.getPrdtypeName());
			}
			referItemVOs.add(referItemVO);
			
			referItemVO = new ReferItemVO();
			referItemVO.setItemkey("brandId");
			if (vo.getBrandId() == null) {
				referItemVO.setId("");
				referItemVO.setValue("");
			} else {
				referItemVO.setId(vo.getBrandId().toString());
				referItemVO.setValue(vo.getBrandName());
			}
			referItemVOs.add(referItemVO);
			
			referItemVO = new ReferItemVO();
			referItemVO.setItemkey("price");
			referItemVO.setId("");
			if (vo.getPrice() == null) {
				referItemVO.setValue("");
			} else {
				referItemVO.setValue(vo.getPrice().toString());
			}
			referItemVOs.add(referItemVO);
			
			referDataVO.setDatalist(referItemVOs);
			*/

			referDataVO.setItemdatalist(itemDataList);
			
			rsList.add(referDataVO);
		}
		
		return rsList;
	}

}
